package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Brank;
import com.stylefeng.guns.modular.system.service.IBrankService;
import com.stylefeng.guns.modular.system.warpper.BrankWarpper;

/**
 * yybtj控制器
 *
 * @author fengshuonan
 * @Date 2018-05-30 12:44:49
 */
@Controller
@RequestMapping("/brank")
public class BrankController extends BaseController {

    private String PREFIX = "/system/brank/";

    @Autowired
    private IBrankService brankService;

    /**
     * 跳转到yybtj首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "brank.html";
    }

    /**
     * 跳转到添加yybtj
     */
    @RequestMapping("/brank_add")
    public String brankAdd() {
        return PREFIX + "brank_add.html";
    }

    /**
     * 跳转到修改yybtj
     */
    @RequestMapping("/brank_update/{brankId}")
    public String brankUpdate(@PathVariable Integer brankId, Model model) {
        Brank brank = brankService.selectById(brankId);
        model.addAttribute("item",brank);
        LogObjectHolder.me().set(brank);
        return PREFIX + "brank_edit.html";
    }

    /**
     * 获取yybtj列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String name) {
    	Page<Brank> page = new PageFactory<Brank>().defaultPage();
    	List<Map<String, Object>> branks = brankService.selectMapsByName(page,name);
    	page.setRecords((List<Brank>) new BrankWarpper(branks).warp());
        return super.packForBT(page);
    }

    /**
     * 新增yybtj
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Brank brank) {
        brankService.insert(brank);
        return SUCCESS_TIP;
    }

    /**
     * 删除yybtj
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer brankId) {
        brankService.deleteById(brankId);
        return SUCCESS_TIP;
    }

    /**
     * 修改yybtj
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Brank brank) {
        brankService.updateById(brank);
        return SUCCESS_TIP;
    }

    /**
     * yybtj详情
     */
    @RequestMapping(value = "/detail/{brankId}")
    @ResponseBody
    public Object detail(@PathVariable("brankId") Integer brankId) {
        return brankService.selectById(brankId);
    }
}
